<?php
// +----------------------------------------------------------------------
// |Third.php
// +----------------------------------------------------------------------
// |Data:2021-03-19 10:01 上午
// +----------------------------------------------------------------------
namespace app\home\controller;

use think\Db;
class Third extends Base{

    /**
     * 获取文章地址
     * @return \think\response\Json
     * @throws \think\Exception
     */
    public function getUrl(){
        $rsp = ['code' => 0, 'msg' => 'fail', 'data' => ''];

        $id = input('id', 0);
      
        if (empty($id)){
            $rsp['msg'] = '参数缺失';
            return json($rsp);
        }

        $info = Db::name('archives')->where([
                'aid'     => $id,
                'is_del'      => 0,
            ])->find();   
         $A =    Db::name('product_content')->field('content,aid')->where('aid', '=', $id)->find();
        //  $arr =[];
        //   foreach ($A  as $v){
        //       if (!empty($v['content'])){
        //           $arr[ $v['aid']] = 1;

        //       }else{
        //           $arr[ $v['aid']] = 0;

        //       }
        //   }
        // if()
            // dump($A['content']);exit;
        if (!$info){
            $rsp['msg'] = '该记录不存在或已被删除';
            return json($rsp);
        }

        $rsp['code'] = 200;
        $rsp['msg'] = 'ok';
        $data['url'] = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/index.php?m=home&c=View&a=index&aid='.$id.'&admin_id=1&t='.time();
        $data['title'] = $info['title'];
        $data['id'] = $info['aid'];
        $data['is_video'] = $A['content']?1:0;
        $rsp['data'] = $data;
        return json($rsp);
    }
}